FROM devcloud-cn-north-1.jcr.service.jdcloud.com/inscode:langvjava1.8 as app

# 用户工作空间，用于打包到前端工作空间地址
ENV IDE_DIR ide
ENV IDE_EXT_DIR ext
ENV WORKSPACE_DIR workspace
ENV EXTENSION_DIR extensions
ENV EXT_MODE js
ENV DEBIAN_FRONTEND=noninteractive
ENV PROJECT_DIR workspace
ENV USER_NAME admin
ENV USER_EMAIL admin@devide

RUN mkdir -p /${IDE_DIR} &&\
    mkdir -p /${IDE_DIR}/${WORKSPACE_DIR} &&\
    mkdir -p /${IDE_DIR}/${IDE_EXT_DIR} &&\
    mkdir -p /${IDE_DIR}/${EXTENSION_DIR}

COPY sources.list /etc/apt/sources.list
RUN apt-get clean
RUN apt-get update --fix-missing && apt-get install -y \
    novnc x11vnc xvfb git-core git vim wget lsof curl locales openjdk-17-jdk fonts-wqy-zenhei language-pack-zh-hans apt-utils libcairo2-dev net-tools sshpass dnsutils iproute2 jq iputils-ping telnet && rm -rf /var/lib/apt/lists/*

RUN localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 && \
    locale-gen en_US.UTF-8 && \
    LC_ALL=en_US.UTF-8 && \
    LANG=en_US.UTF-8 && \
    LANGUAGE=en_US.UTF-8
# 时区更新
RUN ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && dpkg-reconfigure -f noninteractive tzdata


RUN echo "zh_CN.UTF-8 UTF-8" >>  /etc/locale.gen && \
    echo "zh_CN GB2312" >> /etc/locale.gen && \
    locale-gen
#中文语言设置
RUN echo 'LANG="zh_CN.UTF-8"' >> /etc/default/locale
RUN echo 'LANGUAGE="zh_CN:zh:en_US:en"' >> /etc/default/locale
RUN echo 'en_US.UTF-8 UTF-8' >> /var/lib/locales/supported.d/local
RUN echo 'zh_CN.UTF-8 UTF-8' >> /var/lib/locales/supported.d/local
RUN echo 'zh_CN.GBK GBK' >> /var/lib/locales/supported.d/local
RUN echo 'zh_CN GB2312' >> /var/lib/locales/supported.d/local
RUN locale-gen
#RUN echo 'export LANG="zh_CN.UTF-8"' >> ~/.bashrc && \
#    echo 'export LANGUAGE="zh_CN:zh"' >> ~/.bashrc

#RUN git clone https://gitcode.net/mirrors/robbyrussell/oh-my-zsh.git /root/.oh-my-zsh \
#    && cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc \
#    && chsh -s /bin/zsh
#RUN sed  -i "s/\$(git_prompt_info)//g" ~/.oh-my-zsh/themes/robbyrussell.zsh-theme

RUN ln -s /usr/local/bin/pip3.8 /usr/bin/pip3.8
RUN rm -fr /root/.npmrc && \
    rm -fr /root/.bashrc

#COPY inscode-output/ /release/inscode-output/
#COPY out/release-standalone /release/inscode-ide
COPY upm_1.0_linux_amd64.deb /tmp/upm_1.0_linux_amd64.deb

#创建软件依赖源目录
RUN mkdir -p /mnt/scratch

#创建挂载软件依赖源的目录
RUN mkdir -p /root/.cache/pip && \
    mkdir -p /root/.npm && \
    mkdir -p /nix && \
    mkdir -p /root/.m2/repository && \
    mkdir -p /root/.cargo/registry && \
    mkdir /root/.pip && \
    mkdir -p /release && \
    mkdir /plugins && \
    mkdir -p /root/.cache/base_env && \
    mkdir /root/.local && \
    mkdir /root/.nix-defexpr

#依赖资源配置文件
#COPY settings.xml /root/.m2/settings.xml
COPY pip.conf /root/.pip/pip.conf

# 初始化 nix  用户资源目录
#COPY .nix-channels /root/.nix-channels
#COPY nix /root/.cache/nix
#COPY nix-index /root/.cache/nix-index
#COPY shell.nix /root/.cache/shell.nix
#RUN cd /root && ln -s /nix/var/nix/profiles/default .nix-profile
#RUN mkdir /root/.local
#RUN mkdir /root/.nix-defexpr && \
#    cd /root/.nix-defexpr && ln -s /root/.local/state/nix/profiles/channels channels


#安装 upm 软件管理源
RUN dpkg -i /tmp/upm_1.0_linux_amd64.deb

# 构建用户 bash 环境
RUN groupadd nixbld
#COPY .lang-bashrc /root/.bashrc
#COPY .profile /root/.profile

#IDE配置
#COPY settings.json /tmp/settings.json
#COPY argv.json /tmp/argv.json
#COPY clp /tmp/clp
#COPY languagepacks.json /tmp/languagepacks.json

#COPY  nix /root/.config/nix
COPY .lang-init.sh /root/.init.sh
#COPY auto_git.sh /root/.cache/auto_git.sh
#COPY mysql-init.sh /tmp/mysql-init.sh
#RUN  chmod a+x /root/.cache/auto_git.sh
#COPY out/extensions /tmp/extensions
RUN chmod a+x /root/.init.sh
RUN mkdir -p /root/.history
WORKDIR /root/$PROJECT_DIR
RUN echo "net.ipv6.conf.all.disable_ipv6 = 1" >> /etc/sysctl.conf && \
    echo "net.ipv6.conf.default.disable_ipv6 = 1" >> /etc/sysctl.conf && \
    echo "net.ipv6.conf.lo.disable_ipv6=1" >> /etc/sysctl.conf
RUN sysctl -p
RUN update-java-alternatives --set java-1.8.0-openjdk-amd64
EXPOSE 8000

CMD [ "/bin/bash","-c", "/root/.init.sh" ]
